home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / wb / Tripppin.lha / Tripppin / source / Paul.h < prev    next >
C/C++ Source or Header  |  1991-01-10  |  7KB  |  254 lines

  1. /*
  2. The following declarations are used in most every program written by Paul
  3. Kienitz.  Generally, I use a symbol table file which includes exec/exec.h,
  4. libraries/dosextens.h, stdio.h, string.h, and this, which pulls in
  5. functions.h.  I have a separate symbol file for intuition/intuitionbase.h,
  6. which pulls in all the other intuition/ files.
  7. */
  8.  
  9. #ifndef PAUL_DOT_AITCH
  10. #define PAUL_DOT_AITCH
  11.  
  12. #ifdef _STDIO_H            /* aztec 3.6 version */
  13. #define __STDIO_H
  14. #endif
  15.  
  16. #ifdef __STDIO_H        /* ansi version */
  17. #define put(S) fputs(S, stdout)
  18. #endif
  19.  
  20.  
  21. #define null   ((void *) 0L)
  22. #define maxint 0x7fffffffL
  23. #define minint 0x80000000L
  24. /* uppercase is a pain in the wazoo */
  25.  
  26. #define bip(T, B) ((T *) (B << 2))
  27. #define gbip(B)   bip(void, B)
  28. /* B is expected to be of type BPTR or BSTR. */
  29.  
  30. typedef short bool;
  31. #define false ((bool) 0)
  32. #define true  ((bool) 1)
  33.  
  34. typedef unsigned short ushort;
  35. typedef unsigned long  ulong;
  36. typedef unsigned char  ubyte;
  37.  
  38. typedef void *adr;
  39. typedef char *str;
  40.  
  41.  
  42. #define bit(B) (1L << (B))
  43.  
  44. #define import  extern
  45. #define PUBLIC
  46.  
  47. #ifndef private
  48. #define private static
  49. #else
  50. #undef  private
  51. #define private PUBLIC
  52. #endif
  53.  
  54.  
  55. #ifndef _SIZE_T
  56. #define _SIZE_T
  57. typedef unsigned long size_t;
  58. #endif
  59.  
  60.  
  61. #if __STDC__
  62. #define _ANSI_C
  63. #else
  64. #ifdef AZTEC_C
  65. #ifdef __STDC__
  66. #define _ANSI_C
  67. #endif
  68. #endif
  69. #endif
  70. /* the above is BOGUS!!  We need a way to KNOW if it's ansi or not!  The
  71. above assumes that it's always ansi if it's aztec 5.0, regardless of whether
  72. the compiler has been told to not use ansi features!  The compiler normally
  73. defines __STDC__ as zero, not one, unless you use the -at option to turn on
  74. useless "trigraph" parsing. */
  75.  
  76.  
  77. #ifdef _ANSI_C
  78. #define _PROTO(X) X
  79. #define VOLATILE volatile
  80. #define CONST const
  81. #else
  82. #define _PROTO(X) ()
  83. #define VOLATILE 
  84. #define CONST
  85. #endif
  86.  
  87. #define pro(X) _PROTO(x)
  88. /* dunno if I'll use that or not */
  89.  
  90.  
  91.  
  92. #ifdef AZTEC_C
  93.  
  94. #ifndef _ANSI_C
  95.  
  96. /******
  97. Under Aztec 3.6, we have to monkey with functions.h.  The problem is that many
  98. of the functions in there are incorrectly declared.  First, CreateProc and
  99. DeviceProc are declared as returning struct Process pointers when they in
  100. fact return struct MsgPort pointers.  Secondly, all of the DOS functions that
  101. return BPTRs are declared as returning pointers.  And they define
  102. OpenWorkBench as returning a short!  And they mistakenly have OpenFont and
  103. OpenDiskFont returning "struct Font" (which is not defined) instead of struct
  104. TextFont.  Some of these functions can be fixed by #defining Blah as _Blah,
  105. when the glue routine provides both names, and declaring _Blah properly.  For
  106. the others, we use a #define before functions.h to prevent it from defining
  107. them at all.  In 5.0 these problems no longer exist.
  108. */
  109.  
  110. #define CreateProc    ___n_O_ne_XI__st_EN_t____1
  111. #define DeviceProc    ___n_O_ne_XI__st_EN_t____2
  112. #define CreateDir     ___n_O_ne_XI__st_EN_t____3
  113. #define ParentDir     ___n_O_ne_XI__st_EN_t____4
  114. #define DupLock       ___n_O_ne_XI__st_EN_t____5
  115. #define LoadSeg       ___n_O_ne_XI__st_EN_t____6
  116. #define OpenWorkBench ___n_O_ne_XI__st_EN_t____7
  117.  
  118. #define Font TextFont
  119.  
  120. #include <functions.h>
  121.  
  122. #undef CreateProc
  123. #undef DeviceProc
  124. #undef CreateDir
  125. #undef ParentDir
  126. #undef DupLock
  127. #undef LoadSeg
  128. #undef OpenWorkBench
  129.  
  130. #undef Font
  131.  
  132.  
  133. #ifndef LIBRARIES_DOS_H
  134. #define BPTR long
  135. #endif
  136.  
  137. import BPTR CreateDir(), ParentDir(), DupLock(), LoadSeg();
  138.  
  139. import struct MsgPort *CreateProc(), *DeviceProc();
  140.  
  141. import struct Screen *OpenWorkBench();
  142.  
  143. /* the autodocs say don't use the return of OpenWorkBench as a screen pointer
  144. because it might change as soon as you get it.  But sometimes it's useful... */
  145.  
  146. import BPTR _Lock(), _Open(), _Input(), _Output(), _CurrentDir();
  147.  
  148. #define Lock       _Lock
  149. #define Open       _Open
  150. #define Input      _Input
  151. #define Output     _Output
  152. #define CurrentDir _CurrentDir
  153.  
  154. /*
  155. What we really need is different BPTR types that are incompatible for
  156. assignment without casts, yet refuse to be dereferenced as pointers.  Like
  157. FileLockBPTR, SegListBPTR, etc.  But what would these be defined as?
  158. */
  159.  
  160. #else  /* aztec 5.0 and newer */
  161.  
  162. #include <functions.h>        /* define inline calls of rom functions */
  163.  
  164. #endif
  165.  
  166.  
  167. /* AND NOW, convenience stuff:::::::::::::::::::: */
  168. #ifndef _ANSI_C
  169. #ifdef SAVE_ONE_MEASLY_INSTRUCTION_PER_CALL
  170.  
  171. import struct Message *_GetMsg();
  172. import void            _ReplyMsg();
  173. import struct Message *_WaitPort();
  174. import struct Task    *_FindTask();
  175. import void           *_AllocMem();
  176. import void            _FreeMem();
  177.  
  178. #define GetMsg   _GetMsg
  179. #define ReplyMsg _ReplyMsg
  180. #define WaitPort _WaitPort
  181. #define FindTask _FindTask
  182. #define AllocMem _AllocMem
  183.  
  184. /*
  185. There are probably a few other glue routines with two names and wasted
  186. instructions.  (It's like, GetMsg is a jump to _GetMsg.  Why didn't they just
  187. put the two symbols at the same address??  Bozos...)
  188. */
  189. #endif 
  190. #endif ! _ANSI_C
  191.  
  192. #endif AZTEC_C
  193.  
  194.  
  195. #ifdef EXEC_MEMORY_H
  196.  
  197. #define Alloc(S)    AllocMem((long) (S), 0L)
  198. #define AllocC(S)   AllocMem((long) (S), MEMF_CHIP)
  199. #define AllocP(S)   AllocMem((long) (S), MEMF_PUBLIC)
  200. #define AllocZ(S)   AllocMem((long) (S), MEMF_CLEAR)
  201. #define AllocCP(S)  AllocMem((long) (S), MEMF_CHIP | MEMF_PUBLIC)
  202. #define AllocCZ(S)  AllocMem((long) (S), MEMF_CHIP | MEMF_CLEAR)
  203. #define AllocPZ(S)  AllocMem((long) (S), MEMF_PUBLIC | MEMF_CLEAR)
  204. #define AllocCPZ(S) AllocMem((long) (S), MEMF_CHIP | MEMF_PUBLIC | MEMF_CLEAR)
  205. #define NewR(T, R)  ((T *) AllocMem((long) sizeof(T), R))
  206. #define New(T)      NewR(T, 0L)
  207. #define MewC(T)     NewR(T, MEMF_CHIP)
  208. #define NewP(T)     NewR(T, MEMF_PUBLIC)
  209. #define NewZ(T)     NewR(T, MEMF_CLEAR)
  210. #define NewCP(T)    NewR(T, MEMF_CHIP | MEMF_PUBLIC)
  211. #define NewCZ(T)    NewR(T, MEMF_CHIP | MEMF_CLEAR)
  212. #define NewPZ(T)    NewR(T, MEMF_PUBLIC | MEMF_CLEAR)
  213. #define NewCPZ(T)   NewR(T, MEMF_CHIP | MEMF_PUBLIC | MEMF_CLEAR)
  214.  
  215. #endif
  216.  
  217. #define Free(T, A)    FreeMem(A, (long) sizeof(T))
  218.  
  219.  
  220. #ifdef LIBRARIES_DOS_H
  221.  
  222. #define RLock(F) Lock(F, (long) ACCESS_READ)
  223. #define WLock(F) Lock(F, (long) ACCESS_WRITE)
  224. #define OOpen(F) Open(F, (long) MODE_OLDFILE)
  225. #define NOpen(F) Open(F, (long) MODE_NEWFILE)
  226.  
  227. #endif
  228.  
  229.  
  230. #define Forbid() ((*((ubyte **) 4))[295]++)
  231. /* as efficient as assembly; Aztec turns that into two instructions. */
  232.  
  233.  
  234. #ifdef LIBRARIES_DOSEXTENS_H
  235.  
  236. #define ThisProcess() ((*((struct Process ***) 4))[69])
  237. /* equivalent to (struct Process *) SysBase->ThisTask, two instructions. */
  238.  
  239. /** the cowardly safe alternative:
  240. #define ThisProcess() ((struct Process *) FindTask(null))
  241. import struct Task *FindTask _PROTO((const char *name));
  242. */
  243.  
  244. #endif
  245.  
  246.  
  247. #ifdef AZTEC_C     /* remove this for old v3.4 aztec */
  248. #define strcpy _BUILTIN_strcpy
  249. #define strcmp _BUILTIN_strcmp
  250. #define strlen _BUILTIN_strlen
  251. #endif
  252.  
  253. #endif PAUL_DOT_AITCH
  254.